if (typeof Tv_Arte_HeaderInclude == 'undefined') {

    var Tv_Arte_HeaderInclude = {};

	(function()
	{

		// Scopping
        var PUBLIC = Tv_Arte_HeaderInclude;
        var PRIVATE = {};

		/**
		 * =======================================
		 * Group: Private
		 * =======================================
		 */
  		PRIVATE._success = false;

		PRIVATE._getUrlVars = function(url)
		{
		    var vars = [], hash, i;
		    var hashes = url.slice(url.indexOf('?') + 1).split('&');
		    for(i = 0; i < hashes.length; i++)
		    {
		        hash = hashes[i].split('=');
		        vars.push(hash[0]);
		        vars[hash[0]] = hash[1];
		    }
		    return vars;
		};

		PRIVATE._initialize = function()
		{
		    if (typeof jQuery == 'undefined') {
			    var jQueryInterval = null;
			    var script = document.createElement('script');
			    script.setAttribute('type', 'text/javascript');
                script.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');
				document.getElementsByTagName('head')[0].appendChild(script);
				jQueryInterval = setInterval(function() {
     				if (typeof jQuery != 'undefined') {
     					clearInterval(jQueryInterval);
     					PRIVATE._onReady();
     				}
				}, 250);
				return;
			}
   			PRIVATE._onReady();
		};

		PRIVATE._onReady = function()
        {
            var scripts = document.getElementsByTagName('script'), result, GET, ROOT_HTTP, success = false;
            jQuery.each(scripts, function(k, v)
            {
                result = v.src.match(/Tv_Arte_HeaderIncludeJsonp_([0-9a-z]+)_([a-z]{0,2})\.js/);
                if (result != null && result.length == 3) {
                    GET = {id:result[1], lang:result[2]},
					ROOT_HTTP = 'http://www.arte.tv/header-include',
					success = true;
                } else if (v.src.indexOf('Tv_Arte_HeaderInclude.js') != -1) {
                    GET = PRIVATE._getUrlVars(scripts[k].src),
					ROOT_HTTP = scripts[k].src.split('?')[0].replace('/assets/js/Tv_Arte_HeaderInclude.js', ''),
					success = true;
                }
                if (success) {
				 	var linkTag;
				 	jQuery.each(
						['render-style-jsonp.css'],
						function(k, v)
				 		{
					        linkTag = document.createElement('link');
							linkTag.setAttribute('type', 'text/css');
							linkTag.setAttribute('href', ROOT_HTTP + '/assets/css/' + v);
							linkTag.setAttribute('rel', 'stylesheet');
							linkTag.setAttribute('media', 'all');
							document.getElementsByTagName('head')[0].appendChild(linkTag);
		     			}
					);
					jQuery.getJSON(
						ROOT_HTTP + '/render/jsonp.php'
							+ '?id=' + GET.id
							+ '&lang=' + GET.lang
							+ '&callback=?',
						function(e)
						{
       						if (e.success) {
								jQuery('body').prepend(e.html);
							   	PRIVATE._success = true;
								jQuery.each(PRIVATE._successListeners, function(k, v)
							   	{
									if (typeof v == 'function') v.call(Tv_Arte_HeaderInclude);
							   	});
							}
						}
					);
					return false;
                }
            });
        };

        PRIVATE._successListeners = [];

  		/**
		 * end Group: Private
		 *
         * =======================================
		 * Group: Public
		 * =======================================
		 */
		Tv_Arte_HeaderInclude = {

		    addSuccessListener:function(f)
	    	{
                PRIVATE._successListeners.push(f);
	    	},

	    	updateLangHref:function(lang, href)
	    	{
	    	    jQuery('#arte-hi-lang-' + lang).attr('href', href);
	    	}

		};

		PRIVATE._initialize();

	})();

} // endif (typeof Tv_Arte_HeaderInclude == 'undefined')

/**
 * =======================================
 * Usage:
 * =======================================
 *
	Tv_Arte_HeaderInclude.addSuccessListener(function()
	{
		this.updateLangHref('fr', 'http://www.test.fr');
	});
 *
 * end Usage
 *
 */